home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume20 / pegboard < prev    next >
Encoding:
Internet Message Format  |  1989-10-26  |  41.7 KB

  1. Subject:  v20i076:  An electronic office sign-in/signout pegboard
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Richard O'Rourke <uunet!mplex!ror>
  7. Posting-number: Volume 20, Issue 76
  8. Archive-name: pegboard
  9.  
  10. [  I tweaked the Makefile and added the -DBSD stuff; looks like the
  11.    original was for Xenix (/etc/default?) /r$ ]
  12.  
  13. This program can be used to keep track of who is in or out of the
  14. office, and when they are due back.  To be useful, people have to
  15. USE it, but this is true of traditional pegboards as well.  People
  16. here find it friendly enough and pretty much keep the pegboard updated.
  17.  
  18. #! /bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of shell archive."
  25. # Contents:  Makefile README default.peg dot.pegrc peg.h peg.h.ansi
  26. #   peg.man peg.y pegboard.hdr pegio.c tfix.c
  27. # Wrapped by rsalz@prune.bbn.com on Fri Oct 27 13:08:48 1989
  28. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  29. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  30.   echo shar: Will not clobber existing file \"'Makefile'\"
  31. else
  32. echo shar: Extracting \"'Makefile'\" \(477 characters\)
  33. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  34. XOBJS = peg.o tfix.o pegio.o
  35. XSRCS = peg.c tfix.c pegio.c
  36. XBINDIR = /usr/lbin
  37. X
  38. X#DEFS=-DBSD -DLPNMAX=128
  39. XOPTS = -O $(DEFS)
  40. X#
  41. X# Name of executable
  42. XBNAME = peg
  43. X
  44. X$(BNAME):    $(OBJS) peg.h
  45. X    cc $(OPTS) -o $(BNAME) $(OBJS)
  46. X
  47. Xpeg.o:    peg.c peg.h
  48. X    cc $(OPTS) -c peg.c
  49. X
  50. Xtfix.o:    tfix.c peg.h
  51. X    cc $(OPTS) -c tfix.c
  52. X
  53. Xpegio.o:    pegio.c peg.h
  54. X    cc $(OPTS) -c pegio.c
  55. X
  56. Xclean:
  57. X    rm $(OBJS)
  58. Xinstall:
  59. X    mv peg $(BINDIR)/peg
  60. X    mv default.peg /etc/default/peg
  61. Xlint:
  62. X    lint -pubx $(SRCS) >lint.out
  63. X
  64. Xpeg.c: peg.y
  65. END_OF_FILE
  66. if test 477 -ne `wc -c <'Makefile'`; then
  67.     echo shar: \"'Makefile'\" unpacked with wrong size!
  68. fi
  69. # end of 'Makefile'
  70. fi
  71. if test -f 'README' -a "${1}" != "-c" ; then 
  72.   echo shar: Will not clobber existing file \"'README'\"
  73. else
  74. echo shar: Extracting \"'README'\" \(1460 characters\)
  75. sed "s/^X//" >'README' <<'END_OF_FILE'
  76. XPeg is an online pegboard.  It is used to see if someone is in or
  77. Xout of the office and when they are expected back.  Do "make install"
  78. Xafter you get it to compile.
  79. X
  80. XThere is at least 1 incompatibilty problem you may encounter, fcntl
  81. Xtype locking is used.  The functions are "pblock()" and "pbunlock()"
  82. Xin "pegio.c".  "getopts()" is required, if you don't have it you can
  83. Xget it from an archive site.  You will want yacc if you are going to
  84. Xdo any major additions to the source.  There is nothing in the makefile
  85. Xto install the man page, you will have to do that by hand.
  86. X
  87. XYou may find it useful for other things too, the verify "-v" option
  88. Xhas possibilities, eg.:
  89. X--------
  90. X#
  91. X# Mail list of meeting dates and times to users
  92. X#
  93. XSDATE="Monday 8"    # The first meeting, next Monday at 8:00A
  94. XUSERLIST=administrators
  95. XSUBJECT=Meetings
  96. XMESSAGE="Future meeting dates and times, please don't be late:\n"
  97. X
  98. X{
  99. X    echo $MESSAGE
  100. X    #
  101. X    # 6 monthly meetings, each on the day given in SDATE
  102. X    for OFFSET in 0 4 8 12 16 20
  103. X    do
  104. X        peg -v $SDATE + ${OFFSET}w
  105. X    done
  106. X}    | mail -s $SUBJECT $USERLIST
  107. X--------
  108. X
  109. XPeg needs some way of recognizing dates that are holidays, so they can
  110. Xbe skipped when the "-t" option is given.  This is not covered in the
  111. Xcurrent implementation.  If someone cares to add this feature please
  112. Xsend us the additions.
  113. X
  114. XThis was my first bout with yacc, and I'm sure there are better ways
  115. Xto do what I did.  Constructive criticism is welcome, send to:
  116. X
  117. Xuunet!mplex!ror
  118. END_OF_FILE
  119. if test 1460 -ne `wc -c <'README'`; then
  120.     echo shar: \"'README'\" unpacked with wrong size!
  121. fi
  122. # end of 'README'
  123. fi
  124. if test -f 'default.peg' -a "${1}" != "-c" ; then 
  125.   echo shar: Will not clobber existing file \"'default.peg'\"
  126. else
  127. echo shar: Extracting \"'default.peg'\" \(165 characters\)
  128. sed "s/^X//" >'default.peg' <<'END_OF_FILE'
  129. X#
  130. X# NOUNPEG for a given tty will result in users NOT being unpegged
  131. X# when they log on via that tty.  Useful for modem lines.
  132. X
  133. X#NOUNPEG /dev/tty1A
  134. XPEGDIR=/usr/spool
  135. END_OF_FILE
  136. if test 165 -ne `wc -c <'default.peg'`; then
  137.     echo shar: \"'default.peg'\" unpacked with wrong size!
  138. fi
  139. # end of 'default.peg'
  140. fi
  141. if test -f 'dot.pegrc' -a "${1}" != "-c" ; then 
  142.   echo shar: Will not clobber existing file \"'dot.pegrc'\"
  143. else
  144. echo shar: Extracting \"'dot.pegrc'\" \(57 characters\)
  145. sed "s/^X//" >'dot.pegrc' <<'END_OF_FILE'
  146. Xmon 8:30
  147. Xtue 8:30
  148. Xwed 8:30
  149. Xthu 8:30
  150. Xfri 8:30
  151. Xsat -
  152. Xsun -
  153. END_OF_FILE
  154. if test 57 -ne `wc -c <'dot.pegrc'`; then
  155.     echo shar: \"'dot.pegrc'\" unpacked with wrong size!
  156. fi
  157. # end of 'dot.pegrc'
  158. fi
  159. if test -f 'peg.h' -a "${1}" != "-c" ; then 
  160.   echo shar: Will not clobber existing file \"'peg.h'\"
  161. else
  162. echo shar: Extracting \"'peg.h'\" \(1322 characters\)
  163. sed "s/^X//" >'peg.h' <<'END_OF_FILE'
  164. X#include <stdio.h>
  165. X#include <string.h>
  166. X#include <pwd.h>
  167. X#include <time.h>
  168. X#include <signal.h>
  169. X#include <fcntl.h>
  170. X#include <ctype.h>
  171. X#include <errno.h>
  172. X
  173. X#define HOMENV    "HOME"
  174. X#define PEGRCFN    ".pegrc"
  175. X#define PBFNM    "pegboard"
  176. X#define RCFNAM    "/etc/default/peg"
  177. X
  178. X#define PBDIR    "/usr/spool"
  179. X#define TMPLATE    "PEGCOPY.XXXXXX"
  180. X#define PEGBOARD    "/usr/spool/pegboard"
  181. X#define PEGLOCK    "/tmp/LCK.pegboard"
  182. X#define OKCS    \
  183. X " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ +,~@0123456789"
  184. X
  185. Xtypedef void int;
  186. X
  187. Xvoid    use    ( );
  188. Xvoid    copytime( );
  189. Xvoid    dround    ( );
  190. Xvoid    faterr    ( );
  191. Xvoid    finit    ( );
  192. Xvoid    specerr    ( );
  193. Xchar    *igets    ( );
  194. Xchar    *lows    ( );
  195. Xchar    *getenv    ( );
  196. Xchar    *ttyname( );
  197. Xchar    *fixargs( );
  198. Xchar    *malloc    ( );
  199. Xchar    *mktemp    ( );
  200. Xint    cleanup    ( );
  201. Xint    chkpeg    ( );
  202. Xlong    fixstrt    ( );
  203. Xlong    fixday    ( );
  204. Xlong    fixday    ( );
  205. Xlong    fixhm    ( );
  206. Xlong    fixymd    ( );
  207. Xlong    time    ( );
  208. Xlong    lseek    ( );
  209. Xstruct    passwd    *getpwuid( );
  210. Xstruct    passwd    *getpwnam( );
  211. Xstruct    tm *localtime    ( );
  212. X
  213. Xextern int    opterr;
  214. Xextern int    optind;
  215. Xextern int    eod;
  216. Xextern int    admupd;
  217. Xextern int    quiet;
  218. Xextern int    vrbose;
  219. Xextern int    normpeg;
  220. Xextern char    lb[];
  221. Xextern char    *invkst;
  222. Xextern char    *pegfnm;
  223. Xextern char    *pegdir;
  224. Xextern char    *optarg;
  225. Xextern char    *sys_errlist[];
  226. Xextern int    sys_nerr;
  227. Xextern int    errno;
  228. Xextern long    duback;
  229. Xextern long    starts[];
  230. Xextern struct    tm today;
  231. X
  232. END_OF_FILE
  233. if test 1322 -ne `wc -c <'peg.h'`; then
  234.     echo shar: \"'peg.h'\" unpacked with wrong size!
  235. fi
  236. # end of 'peg.h'
  237. fi
  238. if test -f 'peg.h.ansi' -a "${1}" != "-c" ; then 
  239.   echo shar: Will not clobber existing file \"'peg.h.ansi'\"
  240. else
  241. echo shar: Extracting \"'peg.h.ansi'\" \(1500 characters\)
  242. sed "s/^X//" >'peg.h.ansi' <<'END_OF_FILE'
  243. X#include <stdio.h>
  244. X#include <string.h>
  245. X#include <pwd.h>
  246. X#include <time.h>
  247. X#include <signal.h>
  248. X#include <fcntl.h>
  249. X#include <ctype.h>
  250. X#include <errno.h>
  251. X
  252. X#define HOMENV    "HOME"
  253. X#define PEGRCFN    ".pegrc"
  254. X#define PBFNM    "pegboard"
  255. X#define RCFNAM    "/etc/default/peg"
  256. X
  257. X#define PBDIR    "/usr/spool"
  258. X#define TMPLATE    "PEGCOPY.XXXXXX"
  259. X#define PEGBOARD    "/usr/spool/pegboard"
  260. X#define PEGLOCK    "/tmp/LCK.pegboard"
  261. X#define OKCS    " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\
  262. X+,~@0123456789"
  263. X
  264. Xvoid    use    ( );
  265. Xvoid    copytime( );
  266. Xvoid    dround    ( long * );
  267. Xvoid    faterr    ( char * );
  268. Xvoid    finit    ( FILE *, char *[] );
  269. Xvoid    specerr    ( char * );
  270. Xchar    *igets    ( char [], int, int );
  271. Xchar    *lows    ( char * );
  272. Xchar    *getenv    ( char * );
  273. Xchar    *ttyname( int );
  274. Xchar    *fixargs( char *[] );
  275. Xchar    *malloc    ( unsigned );
  276. Xchar    *mktemp    ( char * );
  277. Xint    cleanup    ( );
  278. Xint    chkpeg    ( unsigned short );
  279. Xlong    fixstrt    ( char * );
  280. Xlong    fixday    ( long );
  281. Xlong    fixday    ( long );
  282. Xlong    fixhm    ( long, long );
  283. Xlong    fixymd    ( long, long, long );
  284. Xlong    time    ( long * );
  285. Xlong    lseek    ( int, long, int );
  286. Xstruct    passwd    *getpwuid( int );
  287. Xstruct    passwd    *getpwnam( char * );
  288. Xstruct    tm *localtime    ( long * );
  289. X
  290. Xextern int    opterr;
  291. Xextern int    optind;
  292. Xextern int    eod;
  293. Xextern int    admupd;
  294. Xextern int    quiet;
  295. Xextern int    vrbose;
  296. Xextern int    normpeg;
  297. Xextern char    lb[];
  298. Xextern char    *invkst;
  299. Xextern char    *pegfnm;
  300. Xextern char    *pegdir;
  301. Xextern char    *optarg;
  302. Xextern char    *sys_errlist[];
  303. Xextern int    sys_nerr;
  304. Xextern int    errno;
  305. Xextern long    duback;
  306. Xextern long    starts[];
  307. Xextern struct    tm today;
  308. X
  309. END_OF_FILE
  310. if test 1500 -ne `wc -c <'peg.h.ansi'`; then
  311.     echo shar: \"'peg.h.ansi'\" unpacked with wrong size!
  312. fi
  313. # end of 'peg.h.ansi'
  314. fi
  315. if test -f 'peg.man' -a "${1}" != "-c" ; then 
  316.   echo shar: Will not clobber existing file \"'peg.man'\"
  317. else
  318. echo shar: Extracting \"'peg.man'\" \(7450 characters\)
  319. sed "s/^X//" >'peg.man' <<'END_OF_FILE'
  320. X.tr _
  321. X.TH PEG 1 "mplex"
  322. X.SH NAME
  323. X.I "peg"
  324. X\- pegboard system
  325. X.SH SYNTAX
  326. X.RB peg
  327. X[\-u|i
  328. X.I user
  329. X]
  330. X[\-c 
  331. X.I text
  332. X] [-lnqtvx] [+N[m|h|d|w] [H[:[M]][p]] [[[Y]/M]/D] [day] [month mday]
  333. X.SH OPTIONS
  334. X.TP 12
  335. X.BR \-q
  336. Xsuppress heading when reporting, suppress printing of date when updating
  337. X.TP
  338. X.BR \-u user
  339. Xprint specific user's pegboard entry 
  340. X.TP
  341. X.BR \-i user
  342. X(interrogate) returns a value of 0 if the user is on the pegboard, 1 if not
  343. X.TP
  344. X.BR \-c text
  345. Xmay be used to add a comment that is printed with the pegboard
  346. X.TP
  347. X.BR \-t
  348. XLog off until tomorrow.
  349. XThe file ".pegrc" in the invoking users home directory is consulted
  350. Xto get the time of day the user starts work.
  351. X.TP
  352. X.BR \-v
  353. XVerify only, with this option the time and date arguments are parsed and
  354. Xthe target time is printed.
  355. XThe pegboard is
  356. X.B not
  357. Xupdated nor is the invoker logged off.
  358. X.TP
  359. X.BR \-x
  360. XRemove the invoking users peg.
  361. XIt is not desirable for this option to work when 
  362. X.I peg
  363. Xis invoked from
  364. Xcertain ttys, specifically modems and some network ports.
  365. XThis situation occurs when "peg -x" is put in the system
  366. X.I .profile,
  367. X(or equivalent) and a user dials in on a modem port.
  368. XA facility is provided to avoid this in the file
  369. X.I /etc/default/peg
  370. X( see
  371. X.BR FILES
  372. Xheading below).
  373. X.TP
  374. X.BR \-n
  375. Xdon't log off after updating pegboard
  376. X.TP
  377. X.BR \-l
  378. XPrints long format
  379. X.SH DESCRIPTION
  380. X.I peg
  381. Xmaintains a list of users who have logged off the system (a 
  382. X.I pegboard
  383. X), and dates and times of when they intend return to the site.
  384. XThe default action when no arguments are given is to print the
  385. Xpegboard contents on standard output.
  386. XThe -u option may be used to print the pegboard entry for a
  387. Xspecific user.
  388. X.P
  389. XContext of arguments is dependent on their format.
  390. XArguments that contain a "/" character are taken to be a date,
  391. Xand one or two "/"'s may be present.
  392. XIn the case of one, "MM/DD" is taken as a month and a day.
  393. X"YY/MM/DD" is taken as year month and day.
  394. X.P
  395. XArguments that contain a ":" are taken as a time, and only one
  396. X":" may be present.
  397. X"HH:MM" is taken as hour and minute.
  398. XA single argument is taken to be an hour in the current day.
  399. XHours are in 24 hour format, unless the argument is suffixed with the
  400. Xletter "p", in which case the time is assumed to be after 12 noon.
  401. XFinally, a full date and time specification may be given by
  402. Xproviding both arguments, in either order.
  403. X.P
  404. XNumeric arguments may be preceded by a "+", in this case
  405. Xthe argument is taken as a "relative" quantity of time.
  406. XThere may be an optional modifier after relative arguments,
  407. Xlegal modifiers are "m", "h", "d" and "w".
  408. X.TP
  409. X.BR m
  410. Xthe offset is taken as a number of minutes from the current time
  411. X.TP
  412. X.BR h
  413. Xthe offset is taken as a number of hours from the current time (default)
  414. X.TP
  415. X.BR d
  416. Xthe offset is taken as a number of days from the current date
  417. X.TP
  418. X.BR w
  419. Xthe offset is taken as a number of weeks from the current date
  420. X.P
  421. XIf a modifier is not given and the argument is in "+n" format,
  422. X"n" is assumed to be a number of hours from the current time
  423. X(the h modifier is redundant).
  424. X.P
  425. XPeg recognizes names of days and months as well.
  426. XMonth names must be followed by a day, ie. Sept 12.
  427. XThe next occurrence of a day or month/day combination specified is assumed.
  428. XSo specifying Tue on a Wednesday results in Tuesday of next week being
  429. Xthe specified day.
  430. XSimilarly, giving a month/day that has already gone by results in that day
  431. Xin the next year being the specified date.
  432. X.P
  433. XAny (reasonable) number of arguments may be given.
  434. XThe effect of multiple arguments is additive, so specifying more
  435. Xthan one absolute date or time will not likely yield expected results.
  436. XMixing one absolute date with some number of relative type arguments
  437. Xhas the effect of adding the relative arguments to the absolute.
  438. X.P
  439. XAfter the pegboard is updated (and the -n, -x, -i or -v options
  440. Xwere not given),
  441. Xall processes in the process group are sent the signal SIGKILL.
  442. X.P
  443. X.I "peg"
  444. Xshould be run with the "-x" option in the system
  445. X.I .profile
  446. Xso that each time the a user logs onto the system their pegboard entry
  447. Xis expunged.
  448. X.P
  449. X.SH EXAMPLES
  450. X.TP 20
  451. X.BR "peg 99/1/12 14:00"
  452. XLog off and peg invoking user to be back January 12, 1999, at 2:00 pm
  453. X.TP 20
  454. X.BR "peg 2:00p 99/1/12"
  455. XSame as above
  456. X.TP 20
  457. X.BR "peg 3/10"
  458. XLog off and peg invoking user to be back March 10 at the current time.
  459. XIf March 10th has passed then March 10th next year is assumed.
  460. X.TP 20
  461. X.BR "peg +2"
  462. XLog off and peg invoking user to be back 2 hours from current time
  463. X.TP 20
  464. X.BR "peg 2:00p"
  465. XLog off and peg invoking user to be back at 2pm today
  466. X.TP 20
  467. X.BR "peg +45m"
  468. XLog off and peg invoking user to be back 45 minutes from the current time
  469. X.TP 20
  470. X.BR "peg -t +3d"
  471. XLog off and peg invoking user to be back 3 days from current date at the
  472. Xtime found in the ".pegrc" file in their home directory
  473. X.TP 20
  474. X.BR "peg -t"
  475. XLog off and and peg invoking user to be back on the next day and time that has
  476. Xan entry in the ".pegrc" file.
  477. XDays that have no entry will be skipped over.
  478. X.TP 20
  479. X.BR "peg -t 14"
  480. XLog off and peg invoking user to be back 2:00 pm on the next day specified
  481. Xin their
  482. X.I .pegrc
  483. Xfile.
  484. X.TP 20
  485. X.BR "peg -v +1 +1 +1"
  486. Xprint what time it will be in three hours
  487. X.P
  488. X.SH FILES
  489. X.TP
  490. X.BR /etc/default/peg
  491. X.TP
  492. X.BR /$HOME/.pegrc
  493. XThese files may have default start times for users in the format:
  494. X.P
  495. X.nf
  496. X.sp
  497. XMON 8:00
  498. X.sp .5
  499. XTUE 8:00
  500. X.sp .5
  501. X   .
  502. X.sp .5
  503. X   .
  504. X.sp .5
  505. X   .
  506. X.sp .5
  507. XFRI 8:00
  508. XSAT -
  509. X.sp .5
  510. XSUN -
  511. X.fi
  512. X.P
  513. XIn addition,
  514. X.I "/etc/default/peg"
  515. Xshould contain entries of these formats:
  516. X.P
  517. X.nf
  518. XPEGDIR /usr/spool
  519. X.fi
  520. X.P
  521. XThis variable specifies the directory that peg uses for the pegboard.
  522. XEach machine associated with a common pegboard should have
  523. Xan "/etc/default/peg" file, specifying a common directory in
  524. Xthe PEGDIR variable.
  525. XThe pegbord file in the common directory must be readable and writable
  526. Xby all users.
  527. X.P
  528. X.nf
  529. X.sp .5
  530. XNOUNPEG /dev/ttyxx
  531. X.fi
  532. X.P
  533. X.P
  534. XUsed to specify tty's that override the action of the
  535. X.I "-x"
  536. Xoption.
  537. XIf peg is invoked from a tty that is listed thusly in
  538. X.I "/etc/default/peg"
  539. Xthen the program exits without updating the pegboard.
  540. XPorts that are connected to modems should be listed in this manner.
  541. X.TP 24
  542. X.BR PEGDIR/pegboard.a*
  543. Xholds a copy of the pegboard when update is in progress
  544. X.TP 24
  545. X.BR $HOME/.pegrc
  546. Xdefault start time of day and days of week
  547. X.TP 24
  548. X.BR /etc/passwd
  549. XUsernames etc. are extracted from this file.
  550. XThe users name is assumed to be in the "gecos" field of the passwd entry
  551. X.SH NOTES
  552. XThe pegboard is maintained using
  553. X.I "user id"
  554. Xnumbers.
  555. X.P
  556. XOnly the first 3 letters of day and month names are significant.
  557. X.P
  558. XIf the real user id of the invoking user is 0 and the
  559. X.I "-u"
  560. Xcommand line option
  561. Xis given then the specified users pegboard entry is updated to the date
  562. Xgiven.
  563. XIf the invoking user id is 0 and both the
  564. X.I "-u"
  565. Xand
  566. X.I "-x"
  567. Xoptions are given then the user name specified as the
  568. X.I "-u"
  569. Xargument is removed from the pegboard.
  570. X.P
  571. XWeek and month names etc. in the command line and tokens and variable names
  572. Xin the
  573. X.I ".pegrc"
  574. Xand
  575. X.I "/etc/default/peg"
  576. Xfiles are
  577. X.BR not
  578. Xcase sensitive.
  579. X.I Arguments
  580. Xin the
  581. X.I /etc/default/peg
  582. Xand
  583. X.I .pegrc
  584. Xfiles
  585. X.BR are
  586. Xcase sensitive.
  587. X.P
  588. XComments are restricted to 64 characters, and must be whitespace or printable.
  589. XThey are truncated to 32 characters in the short form to avoid
  590. Xmessing up screens (assuming 80 column ttys).
  591. XThe complete comment may be read by invoking with the "-l" option.
  592. X.P
  593. XIf no PEGDIR variable is found in the
  594. X.I /etc/default/peg
  595. Xfile then the default directory used is
  596. X.I /usr/spool.
  597. X
  598. END_OF_FILE
  599. if test 7450 -ne `wc -c <'peg.man'`; then
  600.     echo shar: \"'peg.man'\" unpacked with wrong size!
  601. fi
  602. # end of 'peg.man'
  603. fi
  604. if test -f 'peg.y' -a "${1}" != "-c" ; then 
  605.   echo shar: Will not clobber existing file \"'peg.y'\"
  606. else
  607. echo shar: Extracting \"'peg.y'\" \(7896 characters\)
  608. sed "s/^X//" >'peg.y' <<'END_OF_FILE'
  609. X%{
  610. X/*
  611. X    peg.y
  612. X
  613. X    Copyright 1989 RFM Microplex Systems Ltd.
  614. X    RFM Microplex Systems Ltd.
  615. X    265 E. 1st Ave.
  616. X    Vancouver, B.C. CANADA
  617. X    V5T 1A7
  618. X    (604)875-1461
  619. X    Fax: (604)875-9029
  620. X    Email: uunet!mplex!ror
  621. X
  622. X    These documents are copyrighted.  However, they may be distributed freely
  623. X    as long as the following is understood and followed:
  624. X
  625. X    A; They may not be distributed for financial or other gain under any
  626. X       circumstances.
  627. X    B; The author(s) and RFM Microplex Systems Ltd. will not be held liable
  628. X       for any damage or loss of data arising from their use
  629. X    C; Anyone who applies improvements or "bug fixes" shall make an attempt
  630. X       to return these changes to the author listed above
  631. X    D. This copyright applies to all of the documents listed below, and any
  632. X       other information created by compilers or other programs that are
  633. X       applied to them:
  634. X            peg.man peg.y tfix.c peg.h pegio.c
  635. X*/
  636. X#include "peg.h"
  637. X
  638. X#define YYSTYPE long
  639. X
  640. Xchar *invkst;    /* Name of the executable    */
  641. Xchar *pegdir;    /* Directory name for various files    */
  642. Xchar *pegfnm;    /* File name where pegs go    */
  643. Xchar *comment;    /* User's reason for leaving, if given    */
  644. Xchar lb[BUFSIZ];    /* Lines for yylex    */
  645. Xint chk;    /* Check run only    */
  646. Xint eod;    /* Log off till tomorrow    */
  647. Xint admupd;    /* Administrator updating mortals peg    */
  648. Xint quiet;    /* No header, don't print time when done    */
  649. Xint vrbse;    /* Verbose output (this is not the opposite of quiet)    */
  650. Xint normpeg;    /* Set if login tty is on no pegout list    */
  651. X/*
  652. X    Start times for invoking user stored here by rcinit
  653. X*/
  654. Xlong starts [] = { -1, -1, -1, -1, -1, -1, -1 };    
  655. Xlong int duback;    /* Running count in seconds of the date determined    */
  656. Xstruct tm today;    /* */
  657. Xstruct    tm *s;
  658. X%}
  659. X%token    NUMBER
  660. X%right    ':'
  661. X%left    '+'
  662. X%right    '/'
  663. X%right    'p'
  664. X%%
  665. Xnothing:
  666. X    |    nothing expr
  667. X        ;
  668. Xexpr:     NUMBER {
  669. X            $$ = fixhm( $1, 0L );
  670. X        }
  671. X    |    NUMBER ':' NUMBER    {
  672. X            $$ = fixhm( $1, $3 );
  673. X        }
  674. X    |    NUMBER ':' NUMBER 'p'    {
  675. X            $$ = fixhm( $1 < 12 ? $1 + 12 : $1 , $3 );
  676. X        }
  677. X    |    NUMBER '/' NUMBER    {
  678. X            $$ = fixymd(
  679. X            (( $1 < today.tm_mon + 1 ||
  680. X            ( $1 == today.tm_mon + 1 && $3 < today.tm_mday ))
  681. X             ? (long)today.tm_year + 1 : (long)today.tm_year ), $1 , $3 );
  682. X        }
  683. X    |    NUMBER '/' NUMBER '/' NUMBER    {
  684. X            $$ = fixymd( $1, $3 , $5 );
  685. X        }
  686. X    |    NUMBER 'p'    {
  687. X            $$ = fixhm( $1 < 12 ? $1 + 12 : $1 , 0L );
  688. X        }
  689. X            
  690. X    |    '+' NUMBER    {
  691. X            s = localtime( &duback );
  692. X            $$ = fixhm( (long)s->tm_hour + $2, (long)s->tm_min );
  693. X        }
  694. X    |    '+' NUMBER 'h'    {
  695. X            s = localtime( &duback );
  696. X            $$ = fixhm( (long)s->tm_hour + $2, (long)s->tm_min );
  697. X        }
  698. X    |    '+' NUMBER 'm'    {
  699. X            s = localtime( &duback );
  700. X            $$ = fixhm( (long)s->tm_hour, (long)s->tm_min + $2 );
  701. X        }
  702. X    |    '+' NUMBER 'd'    {
  703. X            $$ = fixday( $2 );
  704. X        }
  705. X    |    '+' NUMBER 'w'    {
  706. X            $$ = fixday( $2 * 7L );
  707. X        }
  708. X        ;
  709. X%%
  710. X/*
  711. X    BUGS TO FIX:
  712. X        none (ha)
  713. X*/
  714. X
  715. Xmain( argc, argv )
  716. Xint argc;
  717. Xchar *argv[];
  718. X{
  719. X    extern struct    tm today;
  720. X    extern long    duback;
  721. X    extern char    lb[];
  722. X    extern char    *pegfnm;
  723. X    extern char *pegdir;
  724. X    extern char    *invkst;
  725. X    extern char    *optarg;
  726. X    extern char    *sys_errlist[];
  727. X    extern int    sys_nerr;
  728. X    extern int    errno;
  729. X    extern int    eod;
  730. X    extern int    vrbse;
  731. X    extern int    admupd;
  732. X    struct passwd    *rpu = NULL;
  733. X    int i;
  734. X    int exp = 0;
  735. X    extern int    chk;
  736. X    extern int    normpeg;
  737. X    int logout    = 1;
  738. X
  739. X    invkst = (( strrchr( argv[0], '/' ) == NULL )
  740. X    ? argv[0] : strrchr( argv[0], '/' ) + 1 );
  741. X    /*
  742. X        Read "rc" files
  743. X    */
  744. X    pegfnm    =    NULL;
  745. X    comment    =    NULL;
  746. X    pegdir    =    NULL;
  747. X    rcinit( );
  748. X
  749. X#    define LGLOPTS    "c:i:u:lnqtvx"
  750. X    opterr=0;
  751. X    while(( i = getopt( argc, argv, LGLOPTS )) != EOF )    {
  752. X        switch( i )    {
  753. X            /*
  754. X                Suppress start time rounding
  755. X            */
  756. X            case 't':
  757. X                eod++;
  758. X                break;
  759. X            /*
  760. X                Peg invoking user as back at site (delete pegboard entry)
  761. X            */
  762. X            case 'x':
  763. X                exp++;
  764. X                break;
  765. X            /*
  766. X                Report due back date for specified userm unless invoker
  767. X                is root.  If root then diddle other users peg
  768. X            */
  769. X            case 'u':
  770. X                if( ! getuid( ))    {
  771. X                    if( setuid( getpwnam( optarg )->pw_uid ))
  772. X                        faterr( "setuid call failed" );
  773. X                    admupd++;
  774. X                    break;
  775. X                }
  776. X                if(( rpu = getpwnam( optarg )) == NULL )
  777. X                    fprintf( stderr,
  778. X                    "\n%s: user \"%.*s\" not found\n",
  779. X                    invkst, strspn( optarg, OKCS ), optarg );
  780. X                break;
  781. X            /*
  782. X                Don't log the user off after updtaing pegboard
  783. X            */
  784. X            case 'n':
  785. X                logout = 0;
  786. X                break;
  787. X            /*
  788. X                Supress printing of header and time
  789. X            */
  790. X            case 'q':
  791. X                quiet = ( ! quiet );
  792. X                break;
  793. X            /*
  794. X                Check run only, no update, no logout
  795. X            */
  796. X            case 'v':
  797. X                chk++;
  798. X                break;
  799. X            /*
  800. X                Print long format
  801. X            */
  802. X            case 'l':
  803. X                vrbse++;
  804. X                break;
  805. X            /*
  806. X                Read comment
  807. X            */
  808. X            case 'c':
  809. X                comment = ( strlen( optarg ) > BUFSIZ ? "" : optarg );
  810. X                break;
  811. X            /*
  812. X                Interrogate pegboard.  Return 0 if invoker pegged.
  813. X            */
  814. X            case 'i':
  815. X                if( ! *optarg )
  816. X                    exit( 1 );
  817. X                exit( chkpeg( getpwnam( optarg )->pw_uid ));
  818. X
  819. X            case '?':
  820. X            default:
  821. X                fprintf( stderr,
  822. X                "\n%s: Unrecognized option \"%c\"\n",
  823. X                invkst, i );
  824. X                use( );    /* Exits    */
  825. X        }    /* End of switch    */
  826. X    }    /* End of while    */
  827. X
  828. X    if( ! normpeg && exp )    {
  829. X        upddbdf( getuid( ), 1 );
  830. X        exit( 0 );
  831. X    }
  832. X    if ( exp )
  833. X        exit( 0 );
  834. X
  835. X    /* Report for specific user    */
  836. X    if( rpu != NULL)    {
  837. X        report( rpu->pw_uid, quiet );
  838. X        exit( 0 );
  839. X    }
  840. X
  841. X    if((( argc - optind ) < 1 ) && ( ! eod ))    {
  842. X        /* No arguments, report all pegged users    */
  843. X        report( 0, quiet );
  844. X        exit( 0 );
  845. X    }
  846. X
  847. X    lb[0] = '\0';
  848. X    fixargs( &argv[optind] );
  849. X    if(( ! lb[0] ) && eod )
  850. X        sprintf( lb, "+1d" );
  851. X    time( &duback );
  852. X    copytime( localtime( &duback ), &today );
  853. X
  854. X    yyparse( );
  855. X
  856. X    if( chk )    {
  857. X        showtime( &duback );
  858. X        exit( 0 );
  859. X    }
  860. X    /*
  861. X        Update the pegboard.  If it fails then don't die.
  862. X    */
  863. X    if( upddbdf( getuid( ), 0 ))
  864. X        logout = 0;
  865. X    /*
  866. X        Don't die if root
  867. X    */
  868. X    if( ! getuid( ) || admupd )
  869. X        exit( 0 );
  870. X    
  871. X    if( logout )
  872. X        kill( -1, SIGKILL );
  873. X    exit( 0 );
  874. X}
  875. X
  876. Xyylex( )
  877. X{
  878. X    static char *lp;
  879. X    static int init=1;
  880. X    char copy[ BUFSIZ ];
  881. X    int lah1;
  882. X    int lah2;
  883. X    extern char lb[];
  884. X
  885. X    if( init )    {
  886. X        init=( ! init );
  887. X        lp = lb;
  888. X    }
  889. X
  890. X    while( *lp == ' ' || *lp == '\t' )
  891. X        lp++;
  892. X    if( ! *lp || *lp == '\n' )
  893. X        return( 0 );
  894. X    if( isdigit( *lp ))    {
  895. X        sscanf( lp, "%ld", &yylval );
  896. X        lp = ( lp + strspn( lp, "0123456789" ));
  897. X        return( NUMBER );
  898. X    }
  899. X    /*
  900. X        Look for a literal month name and day number
  901. X    */
  902. X    if(( lah1 = ismonth( lp )))    {
  903. X        do    {
  904. X            if( ! *lp++ ) 
  905. X                specerr( "month name must be followed by day of month" );
  906. X        }    while ( ! isdigit( *lp ));
  907. X
  908. X        sscanf( lp, "%d", &lah2 );
  909. X
  910. X        lp = strpbrk( lp, " \t\n" );    /* SP, TAB, NL    */
  911. X        strcpy( copy, lp );    /* If this is NULL that's exactly what we want    */
  912. X        if(( lah1 - 1 ) < today.tm_mon ||
  913. X        (( lah1 - 1 )  == today.tm_mon && lah2 < today.tm_mday ))
  914. X            sprintf( lp, "%d/%d/%d %s", today.tm_year + 1, lah1, lah2, copy );
  915. X        else
  916. X            sprintf( lp, "%d/%d/%d %s", today.tm_year, lah1, lah2, copy );
  917. X        sscanf( lp, "%ld", &yylval );
  918. X        lp = strchr( lp, '/' );
  919. X        return( NUMBER );
  920. X    }
  921. X    if(( lah1 = isday( lp )) != (-1))    {
  922. X        lp = strpbrk( lp, " \t\n" );    /* SP, TAB, NL    */
  923. X        strcpy( copy, lp );    /* If this is NULL that's exactly what we want    */
  924. X        if( lah1 < today.tm_wday )
  925. X            lah1 += 7;
  926. X        lah1 -= today.tm_wday;
  927. X        sprintf( lp, "+%dd %s", lah1, copy );
  928. X    }
  929. X    return( (int)*lp++ );
  930. X}
  931. X
  932. X/*
  933. X    Consolidate string list
  934. X*/
  935. Xchar *fixargs( ss )
  936. Xchar **ss;
  937. X{
  938. X    extern char lb[];
  939. X
  940. X    while( **ss )    {
  941. X        strcat( lb, *ss++ );
  942. X        if(( strlen( lb )) >= BUFSIZ )
  943. X            specerr( "argument string to long" );
  944. X        strcat( lb, " " );
  945. X    }
  946. X    return( lows( lb ));
  947. X}
  948. X
  949. X/*
  950. X    Make s lowercase.
  951. X*/
  952. Xchar *lows( s )
  953. Xchar *s;
  954. X{
  955. X    int i;
  956. X
  957. X    for( i = 0 ; s[i] ; i++ )
  958. X        s[i] = tolower( s[i] );
  959. X    return( s );
  960. X}
  961. X
  962. Xyyerror( m )
  963. Xchar *m;
  964. X{
  965. X    specerr(m);
  966. X}
  967. X
  968. Xvoid specerr( m )
  969. Xchar *m;
  970. X{
  971. X    extern char *invkst;
  972. X
  973. X    fprintf( stderr,
  974. X    "\n%s: Bad specification (%.*s)\n",
  975. X    invkst, strspn( m, OKCS ), m );
  976. X    use( );
  977. X}
  978. X
  979. Xvoid use( s )
  980. Xchar *s;
  981. X{
  982. X    extern char *invkst;
  983. X
  984. X    /* LGLOPTS    "tc:xu:vnqli:"    */
  985. X    fprintf( stderr,
  986. X    "\n%s: maintains an \"on-line pegboard\"\n", invkst );
  987. X    fprintf( stderr,
  988. X    "use: %s [-u|i user -c \"comment\" [-qnxtvl] [date time]\n", invkst );
  989. X
  990. X    exit( 1 );
  991. X}
  992. END_OF_FILE
  993. if test 7896 -ne `wc -c <'peg.y'`; then
  994.     echo shar: \"'peg.y'\" unpacked with wrong size!
  995. fi
  996. # end of 'peg.y'
  997. fi
  998. if test -f 'pegboard.hdr' -a "${1}" != "-c" ; then 
  999.   echo shar: Will not clobber existing file \"'pegboard.hdr'\"
  1000. else
  1001. echo shar: Extracting \"'pegboard.hdr'\" \(1020 characters\)
  1002. sed "s/^X//" >'pegboard.hdr' <<'END_OF_FILE'
  1003. XFrom mplex!ror@uunet.uu.net Tue Apr 18 12:57:54 1989
  1004. XReceived: from BBN.COM by pineapple.bbn.com
  1005. X    id <AA01790@pineapple.bbn.com>; Tue, 18 Apr 89 12:56:01 -0400
  1006. XReceived: from uunet.uu.net by BBN.COM id aa02889; 15 Apr 89 3:21 EDT
  1007. XReceived: from mplex.UUCP by uunet.UU.NET (5.61/1.14) with UUCP 
  1008. X    id AA08484; Sat, 15 Apr 89 03:31:02 -0400
  1009. XFrom: mplex!ror@uunet.UU.NET
  1010. XMessage-Id: <8904150731.AA08484@uunet.UU.NET>
  1011. XTo: uunet!comp-sources-unix@uunet.UU.NET
  1012. XDate: Fri Apr 14 11:55:23 1989
  1013. XStatus: R
  1014. X
  1015. XTo: uunet!comp-sources-unix
  1016. XPath: mplex!ror
  1017. XFrom: ror@mplex.UUCP (Richard O'Rourke)
  1018. XNewsgroups: comp.sources.unix
  1019. XSubject: Online Pegboard
  1020. XMessage-ID: <271@mplex.UUCP>
  1021. XDate: 14 Apr 89 19:55:11 GMT
  1022. XOrganization: RFM Microplex Systems Ltd.
  1023. XLines: 2655
  1024. X
  1025. X
  1026. XThis program can be used to keep track of who is in or out of the
  1027. Xoffice, and when they are due back.  To be useful, people have to
  1028. XUSE it, but this is true of traditional pegboards as well.  People
  1029. Xhere find it friendly enough and pretty much keep the pegboard updated.
  1030. X
  1031. END_OF_FILE
  1032. if test 1020 -ne `wc -c <'pegboard.hdr'`; then
  1033.     echo shar: \"'pegboard.hdr'\" unpacked with wrong size!
  1034. fi
  1035. # end of 'pegboard.hdr'
  1036. fi
  1037. if test -f 'pegio.c' -a "${1}" != "-c" ; then 
  1038.   echo shar: Will not clobber existing file \"'pegio.c'\"
  1039. else
  1040. echo shar: Extracting \"'pegio.c'\" \(10884 characters\)
  1041. sed "s/^X//" >'pegio.c' <<'END_OF_FILE'
  1042. X/*
  1043. X    pegio.c
  1044. X*/
  1045. X
  1046. X#include "peg.h"
  1047. X
  1048. X#define HEADER "User                     Due Back              Comment"
  1049. X#define VHEADER "User    Logged Off        Due Back             Name"
  1050. X
  1051. X/*
  1052. X    Report pegboard for 1 or all users. Call with user number 0 to
  1053. X    get them all.
  1054. X
  1055. X*/
  1056. Xreport( who, nohdr )
  1057. Xint who;    /* User number    */
  1058. Xint nohdr;    /* Quiet    */
  1059. X{
  1060. X    extern char *pegfnm;
  1061. X    extern int    vrbse;
  1062. X
  1063. X    static    char *months [] =    {
  1064. X        "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  1065. X        "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""    };
  1066. X    static    char *days [] =    {
  1067. X        "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"    };
  1068. X
  1069. X    FILE    *pegfd;
  1070. X    char    tb[BUFSIZ+1];
  1071. X    char    cb[BUFSIZ+1];
  1072. X    long    tlo;
  1073. X    long    tdb;
  1074. X    int    u;
  1075. X    struct tm    *j;
  1076. X    struct passwd *p;
  1077. X
  1078. X    if( ! nohdr )
  1079. X            puts( vrbse ? VHEADER : HEADER );
  1080. X    if(( pegfd = fopen( pegfnm, "r" )) == NULL )    {
  1081. X        if( errno == ENOENT )
  1082. X            exit( 0 );
  1083. X        sprintf( tb,
  1084. X        "Cannot read pegboard file \"%s\"", pegfnm );
  1085. X        faterr( tb );    /* Exits.    */
  1086. X    }
  1087. X
  1088. X    while(( fgets( tb, BUFSIZ, pegfd )) != NULL)    {
  1089. X        cb[0] = '\0';
  1090. X        sscanf( tb, "%d %ld %ld %64[ -~\t]\n", &u, &tlo, &tdb, cb );
  1091. X
  1092. X        if(( ! who ) || who == u )    {
  1093. X            p = getpwuid( u );
  1094. X
  1095. X            if( vrbse)    {
  1096. X                j = localtime( &tlo );
  1097. X                printf( "%-7.8s %3s %3s %2d %2d:%02d  ",
  1098. X                p->pw_name,
  1099. X                days[j->tm_wday], months[j->tm_mon],
  1100. X                j->tm_mday, j->tm_hour, j->tm_min );
  1101. X                j = localtime( &tdb );
  1102. X                printf( "%3s %3s %2d %2d:%02d %02d  %.24s\n",
  1103. X                days[j->tm_wday], months[j->tm_mon],
  1104. X                j->tm_mday, j->tm_hour, j->tm_min, j->tm_year,
  1105. X                p->pw_gecos );
  1106. X                if( cb[0] )
  1107. X                    printf(
  1108. X                    "        %.64s\n",
  1109. X                    cb);
  1110. X            }
  1111. X            else    {
  1112. X                j = localtime( &tdb );
  1113. X                printf( "%-24.25s %3s %3s %2d %2d:%02d %02d   %.32s\n",
  1114. X                p->pw_gecos,
  1115. X                days[j->tm_wday], months[j->tm_mon],
  1116. X                j->tm_mday, j->tm_hour, j->tm_min, j->tm_year, cb );
  1117. X            }
  1118. X
  1119. X            if( setpwent( ) == EOF )
  1120. X                faterr( "cannot reset password file" );    /* Exits.    */
  1121. X        }
  1122. X        endpwent( );
  1123. X    }
  1124. X    fclose( pegfd );
  1125. X}
  1126. X
  1127. X/*
  1128. X    Update the pegboard.  Dates gone by do not have the associated
  1129. X    entry deleted but if x is 0 then the users entry is expunged.
  1130. X*/
  1131. Xupddbdf( ru, x )
  1132. Xint ru;    /* User number    *.
  1133. Xint x;    /* Delete peg flag    */
  1134. X{
  1135. X    extern struct    tm today;
  1136. X    extern char    *invkst;
  1137. X    extern char *pegfnm;
  1138. X    extern char *comment;
  1139. X    extern int    eod;    /* Round off to the start of day found in rc    */
  1140. X    extern int    admupd;    /* Administrator updating mortals peg    */
  1141. X    extern int    quiet;    /* Supresses printing of time when done    */
  1142. X    extern long    duback;
  1143. X    extern long starts[];
  1144. X
  1145. X    extern int    cleanup( );
  1146. X    int    ( *clnp )( );
  1147. X    int    pegfd;
  1148. X    int    clfd;
  1149. X    FILE    *tfp;
  1150. X    char    tb[BUFSIZ+1];
  1151. X    char    cb[BUFSIZ+1];
  1152. X    char    tmpf[LPNMAX];
  1153. X    long    tu;
  1154. X    long    bu;
  1155. X    int    nu;
  1156. X    long    stat = 0;
  1157. X
  1158. X    clnp = cleanup;
  1159. X    signal( SIGHUP, clnp );
  1160. X    signal( SIGQUIT, clnp );
  1161. X    signal( SIGINT, clnp );
  1162. X    signal( SIGILL, clnp );
  1163. X    signal( SIGIOT, clnp );
  1164. X    signal( SIGEMT, clnp );
  1165. X    signal( SIGFPE, clnp );
  1166. X    signal( SIGBUS, clnp );
  1167. X    signal( SIGSEGV, clnp );
  1168. X    signal( SIGSYS,    clnp );
  1169. X    signal( SIGTERM, clnp );
  1170. X
  1171. X    umask( 022 );
  1172. X    sprintf( tmpf, "%s/%s", pegdir, TMPLATE );
  1173. X    mktemp( tmpf );
  1174. X    if(( tfp = fopen( tmpf, "w+" )) == NULL )    {
  1175. X        sprintf( tb,
  1176. X        "could not open pegboard copy file \"%s\"", tmpf );
  1177. X        faterr( tb );    /* Exits.    */
  1178. X    }
  1179. X
  1180. X    umask( 0111 );
  1181. X    if(( pegfd = open( pegfnm, O_RDWR )) == (-1))    {
  1182. X        sprintf( tb,
  1183. X        "could not open pegboard file \"%s\"", pegfnm );
  1184. X        faterr( tb );    /* Exits.    */
  1185. X    }
  1186. X
  1187. X    pblock( pegfd );
  1188. X    if( ! x )    {
  1189. X        /*
  1190. X            If pegging out and end of day then round off the time to
  1191. X            the start time for that day (as found in rc)
  1192. X        */
  1193. X        if( eod )    {
  1194. X            int dbdy;
  1195. X            int dy;
  1196. X
  1197. X            stat = 0;
  1198. X            /*
  1199. X                Skip over any days that are not found in rc file.
  1200. X                Check elements of due back times array, starting
  1201. X                from the day in duback, up to a week from then
  1202. X            */
  1203. X            dbdy = dy = localtime( &duback )->tm_wday;
  1204. X            while( starts[dbdy] == ( -1 ))    {
  1205. X                /*
  1206. X                    If wrapped around then no start times are spec'd
  1207. X                */
  1208. X                if( dy == ( dbdy = ( dbdy == 6 ? 0 : ++dbdy )))    {
  1209. X                    stat = 0;
  1210. X                    break;
  1211. X                }
  1212. X                /*
  1213. X                    If the day not spec'd then goto next day
  1214. X                */
  1215. X                stat += 86400;
  1216. X            }
  1217. X            /*
  1218. X                Add in offset to next day with start time, if any
  1219. X                Round to the day boundary and add the start itme for that
  1220. X                day, if any
  1221. X            */
  1222. X            duback += stat;
  1223. X            dround( &duback );
  1224. X            duback +=
  1225. X            (( stat = starts[ localtime( &duback )->tm_wday ]) == ( -1 )
  1226. X            ? 0L : stat );
  1227. X        }
  1228. X        /*
  1229. X            If admin is updating for someone else then keep the old
  1230. X            logout time and comment, unless "-r" given on command line.
  1231. X        */
  1232. X        if( admupd )    {
  1233. X            /*
  1234. X                Admin update
  1235. X            */
  1236. X            while(( igets( tb, BUFSIZ, pegfd )) != NULL )    {
  1237. X                cb[0] = '\0';
  1238. X                sscanf( tb, "%d %ld %ld %64[ -~\t]", &nu, &tu, &bu, cb );
  1239. X                if( ru != nu )
  1240. X                    continue;
  1241. X                break;    /* Found mortals entry    */
  1242. X            }
  1243. X            if( lseek( pegfd, 0L, 0 ) == ( -1 ))    {
  1244. X                sprintf( tb, "could not rewind \"%s\"", pegfnm );
  1245. X                faterr( tb );    /* Exits.    */
  1246. X            }
  1247. X            if( ! *comment )
  1248. X                strcpy( comment, cb );
  1249. X        }
  1250. X        /*
  1251. X            If normal run then put the current time in the logout field
  1252. X        */
  1253. X        else
  1254. X            time( &tu );
  1255. X        if( duback < tu )    {
  1256. X            fprintf( stderr, "%s: too late\n", invkst );
  1257. X            cleanup( 1 );
  1258. X        }
  1259. X        /*
  1260. X            If there is a discrepancy due to daylight savings time between
  1261. X            now and the target date then fix it.
  1262. X        */
  1263. X        if( today.tm_isdst ^ localtime( &duback )->tm_isdst )
  1264. X            duback = ( today.tm_isdst ? duback + 3600 : duback - 3600 );
  1265. X        fprintf( tfp, "%d %ld %ld %.64s\n", ru, tu, duback,
  1266. X        comment == NULL ? "" : comment );
  1267. X    }
  1268. X    while(( igets( tb, BUFSIZ, pegfd )) != NULL )    {
  1269. X        cb[0] = '\0';
  1270. X        sscanf( tb, "%d %ld %ld %64[ -~\t]", &nu, &tu, &bu, cb );
  1271. X        if( ru != nu )
  1272. X            fprintf( tfp, "%d %ld %ld %s\n", nu, tu, bu, cb );
  1273. X    }
  1274. X
  1275. X    if( fseek( tfp, (long)0, 0 ))    {
  1276. X        sprintf( tb, "could not rewind \"%s\"", tmpf );
  1277. X        faterr( tb );    /* Exits.    */
  1278. X    }
  1279. X    sprintf( cb,
  1280. X    "cannot update pegboard \"%s\", there is a copy in \"%s\"",
  1281. X    pegfnm, tmpf );
  1282. X    /*
  1283. X        Clobber the old pegboard
  1284. X    */
  1285. X    if((( clfd = open( pegfnm, O_WRONLY|O_TRUNC )) == (-1))    
  1286. X    || ( close( clfd )))
  1287. X        faterr( cb );    /* Exits.    */
  1288. X    /*
  1289. X        Copy tmp file back onto pegboard
  1290. X    */
  1291. X    if( lseek( pegfd, 0L, 0 ) == ( -1 ))
  1292. X        faterr( cb );
  1293. X    while( fgets( tb, BUFSIZ, tfp ) != NULL )    {
  1294. X        if( write( pegfd, tb, (unsigned)strlen( tb )) == ( -1 ))
  1295. X            faterr( cb );    /* Exits.    */
  1296. X    }
  1297. X
  1298. X    pbunlock( pegfd );
  1299. X
  1300. X    if( close( pegfd ))
  1301. X        faterr( cb );    /* Exits.    */
  1302. X    /*
  1303. X        Clobber tmp file, ensure pegboard available to all
  1304. X    */
  1305. X    if( unlink( tmpf ))
  1306. X        fprintf( stderr, "%s: could not remove file \"%s\" (errno %d)\n",
  1307. X        invkst, tmpf, errno );
  1308. X    chmod( pegfnm, 0666 );    /* rw-rw-rw-    */
  1309. X
  1310. X    if(( ! quiet ) && ( ! x ))
  1311. X        showtime( &duback );
  1312. X    return( 0 );
  1313. X}
  1314. X
  1315. X/*
  1316. X    Read a shorter than n \n terminated line from a fd
  1317. X*/
  1318. Xchar *igets( s, n, fd )
  1319. Xchar *s;
  1320. Xint n;
  1321. Xint fd;
  1322. X{
  1323. X    char *t;
  1324. X
  1325. X    t = s;
  1326. X    while( --n )    {
  1327. X        switch( read( fd, t, 1 ))    {
  1328. X            case 1:
  1329. X                if( *t++ == '\n' )    {    /* EOL?    */
  1330. X                    *t = '\0';
  1331. X                    return( s );
  1332. X                }
  1333. X                continue;
  1334. X
  1335. X            case 0:    /* EOF?    */
  1336. X                return( NULL );
  1337. X
  1338. X            case -1:
  1339. X            default:
  1340. X                sprintf( s,
  1341. X                "error %d reading file descriptor %d",
  1342. X                errno, fd );
  1343. X                faterr( s );    /* Exits.    */
  1344. X        }
  1345. X    }
  1346. X    /*
  1347. X        > n bytes up to next \n in file, return what's collected so far
  1348. X    */
  1349. X    *t = '\0';
  1350. X    return( s );
  1351. X}
  1352. X
  1353. Xrcinit( )
  1354. X{
  1355. X    extern char *pegfnm;
  1356. X    extern char *pegdir;
  1357. X    FILE *rcfp;
  1358. X    char tb[BUFSIZ];
  1359. X
  1360. X    /*
  1361. X        SUN - SAT must use the 0 - 6 slots!
  1362. X    */
  1363. X#    define SUN    0
  1364. X#    define MON    1
  1365. X#    define TUE    2
  1366. X#    define WED    3
  1367. X#    define THU    4
  1368. X#    define FRI    5
  1369. X#    define SAT    6
  1370. X#    define NOPEGTK    7
  1371. X#    define PEGDIR    8
  1372. X
  1373. X    static char *srctkns[] =    {
  1374. X        "sun", "mon", "tue", "wed", "thu", "fri", "sat",
  1375. X         "nounpeg", "pegdir",
  1376. X         "" };
  1377. X    static char *urctkns[] =    {
  1378. X        "sun", "mon", "tue", "wed", "thu", "fri", "sat",
  1379. X         "" };
  1380. X
  1381. X    /*
  1382. X        Read the system rc file, consider it mandatory
  1383. X    */
  1384. X    if(( rcfp = fopen( RCFNAM, "r" )) == NULL )    {
  1385. X        sprintf( tb, "cannot open \"%s\"", RCFNAM );
  1386. X        faterr( tb );    /* Exits.    */
  1387. X    }
  1388. X    finit( rcfp, srctkns );
  1389. X    fclose( rcfp );
  1390. X
  1391. X    /*
  1392. X        Read the users rc file, but ignore if it does not exist
  1393. X    */
  1394. X    sprintf( tb, "%s/%s", getenv( HOMENV ), PEGRCFN );
  1395. X    if(( rcfp = fopen( tb, "r" )) != NULL )
  1396. X        finit( rcfp, urctkns );
  1397. X    fclose( rcfp );
  1398. X    /*
  1399. X        If we did not pick up names in the system default file
  1400. X        then assign the defaults
  1401. X    */
  1402. X    if( pegfnm == NULL )
  1403. X        pegfnm = PEGBOARD;
  1404. X    if( pegdir == NULL )
  1405. X        pegdir = PBDIR;
  1406. X    return( 0 );
  1407. X}
  1408. X
  1409. Xvoid finit( rcfp, tkns )
  1410. XFILE *rcfp;
  1411. Xchar *tkns[];
  1412. X{
  1413. X#    define TSEPCH    " \t=\n"
  1414. X    char tb[BUFSIZ*2];
  1415. X    int i;
  1416. X    char *ttynm;
  1417. X    char *tkargp;
  1418. X    extern char *pegfnm;
  1419. X    extern char *pegdir;
  1420. X    extern int chk;    /* Set for check runs    */
  1421. X    extern int    normpeg;
  1422. X    extern long starts[];
  1423. X
  1424. X    ttynm = ttyname( 0 );
  1425. X
  1426. X    while(fgets( tb, BUFSIZ, rcfp ) != NULL )    {
  1427. X        tkargp = strtok( tb, TSEPCH );
  1428. X        lows( tkargp );
  1429. X        for( i = 0 ; *tkns[i] ; i++ )    {
  1430. X            if( ! strncmp( tb, tkns[i], strlen( tkns[i] )))    {
  1431. X                switch( i )    {
  1432. X                    /*
  1433. X                        Default start times
  1434. X                    */
  1435. X                    case SUN:
  1436. X                    case MON:
  1437. X                    case TUE:
  1438. X                    case WED:
  1439. X                    case THU:
  1440. X                    case FRI:
  1441. X                    case SAT:
  1442. X                        starts[i] = fixstrt( strtok( 0, TSEPCH ));
  1443. X                        continue;
  1444. X                    /*
  1445. X                        Is terminal (modem most likely) on the no peg out list?
  1446. X                    */
  1447. X                    case NOPEGTK:
  1448. X                        tkargp = strtok( 0, TSEPCH );
  1449. X                        if((( ! strcmp( ttynm, tkargp )))
  1450. X                        && ( ! chk ))
  1451. X                            normpeg++;
  1452. X                        continue;
  1453. X                    /*
  1454. X                        Pegboard directory? Get pegboard filename
  1455. X                    */
  1456. X                    case PEGDIR:
  1457. X                        tkargp = strtok( 0, TSEPCH );
  1458. X                        pegfnm =
  1459. X                        malloc((unsigned)
  1460. X                        strlen( tkargp ) + strlen( PBFNM ) + 2 );
  1461. X                        sprintf( pegfnm, "%s/%s", tkargp, PBFNM );
  1462. X                        continue;
  1463. X
  1464. X                    default:
  1465. X                        sprintf( tb,
  1466. X                        "init file \"%s\" garbled", RCFNAM );
  1467. X                        faterr( tb );    /* Exits.    */
  1468. X                }    /* End of switch    */
  1469. X            }    /* End of if    */
  1470. X        }    /* End of for    */
  1471. X    }    /* End of while    */
  1472. X}
  1473. X
  1474. Xpblock( fd )
  1475. Xint fd;
  1476. X{
  1477. X    extern int errno;
  1478. X    struct flock lk;
  1479. X
  1480. X    lk.l_type = F_WRLCK;
  1481. X    lk.l_whence = 0;
  1482. X    lk.l_start = 0L;
  1483. X    lk.l_len = 0L;
  1484. X
  1485. X    if( fcntl( fd, F_SETLK, &lk ) == (-1))    {
  1486. X        char msg[BUFSIZ];
  1487. X        sprintf( msg, "fcntl lock failed on pegboard, errno %d", errno );
  1488. X        faterr( msg );    /* Exits.    */
  1489. X    }
  1490. X    return( 0 );
  1491. X}
  1492. X
  1493. Xpbunlock( fd )
  1494. Xint fd;
  1495. X{
  1496. X    extern char *invkst;
  1497. X    struct flock lk;
  1498. X
  1499. X    lk.l_type = F_UNLCK;
  1500. X    lk.l_whence = 0;
  1501. X    lk.l_start = 0L;
  1502. X    lk.l_len = 0L;
  1503. X
  1504. X    if( fcntl( fd, F_SETLK, &lk ) == (-1))
  1505. X        fprintf( stderr, "%s: fcntl unlock failed on pegboard", invkst );
  1506. X    return( 0 );
  1507. X}
  1508. X
  1509. Xlong fixstrt( s )
  1510. Xchar *s;
  1511. X{
  1512. X    int h;
  1513. X    int m;
  1514. X
  1515. X    if( ! isdigit( *s ))
  1516. X        return( -1L );
  1517. X    sscanf( s, "%d:%d", &h, &m );
  1518. X
  1519. X    return((long)(( h * 3600 ) + ( m * 60 )));
  1520. X}
  1521. X
  1522. Xchkpeg( u )
  1523. Xunsigned short u;
  1524. X{
  1525. X    FILE *pegfd;
  1526. X    char b[30];
  1527. X    int v;
  1528. X
  1529. X    if(( pegfd = fopen( pegfnm, "r" )) == NULL )
  1530. X        return( -1 );
  1531. X
  1532. X    while( fgets( b, 30, pegfd ) != NULL )    {
  1533. X        sscanf( b, "%d", &v );
  1534. X        if( v == u )    {
  1535. X            if( close( pegfd ))
  1536. X                faterr( "system error closing pegboard" );
  1537. X            return( 0 );
  1538. X        }
  1539. X    }
  1540. X    if( close( pegfd ))
  1541. X        faterr( "system error closing pegboard" );
  1542. X    return( 1 );
  1543. X}
  1544. X
  1545. Xvoid faterr( m )
  1546. Xchar *m;
  1547. X{
  1548. X    extern char *invkst;
  1549. X
  1550. X    fprintf( stderr, "%s: %s\n", invkst, m );
  1551. X    perror( "last system error" );
  1552. X    cleanup( errno );
  1553. X}
  1554. X
  1555. Xcleanup( s )
  1556. Xint s;
  1557. X{
  1558. X    exit( s );
  1559. X}
  1560. END_OF_FILE
  1561. if test 10884 -ne `wc -c <'pegio.c'`; then
  1562.     echo shar: \"'pegio.c'\" unpacked with wrong size!
  1563. fi
  1564. # end of 'pegio.c'
  1565. fi
  1566. if test -f 'tfix.c' -a "${1}" != "-c" ; then 
  1567.   echo shar: Will not clobber existing file \"'tfix.c'\"
  1568. else
  1569. echo shar: Extracting \"'tfix.c'\" \(3793 characters\)
  1570. sed "s/^X//" >'tfix.c' <<'END_OF_FILE'
  1571. X/*
  1572. X    tfix.c
  1573. X*/
  1574. X
  1575. X#include "peg.h"
  1576. X
  1577. X/*
  1578. X    Convert two longs representing a target hour and minute into seconds
  1579. X    from the day boundary, and update the running count for that time.
  1580. X
  1581. X*/
  1582. Xlong fixhm( h, m )
  1583. Xlong h;    /* Hours    */
  1584. Xlong m;    /* Minutes    */
  1585. X{
  1586. X    extern struct tm today;
  1587. X    extern long duback;
  1588. X
  1589. X    while( m >= 60 )    {
  1590. X        h += 1;
  1591. X        m -= 60;
  1592. X    }
  1593. X    /*
  1594. X        If the specified time has gone by assume invoker means tomorrow
  1595. X    */
  1596. X    if(( today.tm_year == localtime( &duback )->tm_year )
  1597. X    && ( today.tm_yday == localtime( &duback )->tm_yday )
  1598. X    && ( today.tm_hour > h ))
  1599. X        h += 24;
  1600. X
  1601. X    dround( &duback );
  1602. X    return(( duback += (( m * 60 ) + ( h * 3600 ))));
  1603. X}
  1604. X
  1605. Xvoid dround( t )
  1606. Xlong *t;
  1607. X{
  1608. X    while( (*t) % 3600 )    /* Round back to hour    */
  1609. X        (*t)--;
  1610. X    while( localtime( t )->tm_hour )    /* Then to the day    */
  1611. X        (*t) -= 3600;
  1612. X}
  1613. X
  1614. X/*
  1615. X    Convert 3 arguments (yy/mm/dd) into an offset in seconds from
  1616. X    the current date, and update the running count.
  1617. X
  1618. X    Bugs: Ignores leap seconds
  1619. X*/
  1620. Xlong fixymd( y, m, d )
  1621. Xlong y;    /* Year    */
  1622. Xlong m;    /* Month    */
  1623. Xlong d;    /* Day    */
  1624. X{
  1625. X    extern struct tm today;
  1626. X    extern long duback;
  1627. X    static int modays[] = { 31, 28, 31, 30,  31,  30,  31,  31,  30,  31,
  1628. X        30,  31 };
  1629. X    int i;
  1630. X
  1631. X    /*
  1632. X        Deal with months from 0-11 (caller passes 1-12), check against bounds.
  1633. X    */
  1634. X    if( --m < 0 || m > 11 )
  1635. X        specerr( "illegal month" );
  1636. X    /*
  1637. X        Check if date gone by
  1638. X    */
  1639. X    if( y < today.tm_year
  1640. X    || ( y == today.tm_year && (( m == today.tm_mon && d < today.tm_mday ) ||
  1641. X       ( m < today.tm_mon))))
  1642. X        specerr( "illegal date" );
  1643. X    /*
  1644. X        Check day against bounds
  1645. X    */
  1646. X    if(((( ! ( y % 4 )) && ( y % 100 )) || ( ! ( y % 400 ))))
  1647. X            modays[1] = 29;
  1648. X    if( d < 0 || d > modays[m] )
  1649. X            specerr( "illegal day" );
  1650. X    /*
  1651. X        Convert mm/yy for target year into tm_yday
  1652. X    */
  1653. X    if((( ! ( y % 4 )) && ( y % 100 ))
  1654. X    || ( ! ( y % 400 )))
  1655. X        modays[1] = 29;
  1656. X    else
  1657. X        modays[1] = 28;
  1658. X    for( i = 0 ; i < m ; i++ )
  1659. X        d += modays[i];
  1660. X    d -= today.tm_yday + 1 ;
  1661. X
  1662. X    /*
  1663. X        Count number of leap years between next year and the
  1664. X        target year.
  1665. X    */
  1666. X    for( i = today.tm_year + 1 ; i < y ; i++ )    {
  1667. X        if((( ! ( i % 4 )) && ( i % 100 )) || ( ! ( i % 400 )))
  1668. X            ++d;
  1669. X    }
  1670. X    /*
  1671. X        Get the years offset
  1672. X    */
  1673. X    y=(long)abs((int)( today.tm_year - y ));
  1674. X
  1675. X    /*
  1676. X        If this is a leap year and the target year is not this year
  1677. X        then we need another day...
  1678. X    */
  1679. X    if(((( ! ( today.tm_year % 4 )) &&
  1680. X    ( today.tm_year % 100 )) || ( ! ( today.tm_year % 400 ))) && y )
  1681. X        ++d;
  1682. X    /*
  1683. X        Convert it to days then seconds
  1684. X    */
  1685. X    return( fixday((long)( y * 365 ) + d ));
  1686. X}
  1687. X
  1688. X/*
  1689. X    Return some number of days converted to seconds, added to the
  1690. X    running total in duback.
  1691. X
  1692. X    Externals: duback
  1693. X    Returns: duback
  1694. X*/
  1695. Xlong fixday( d )
  1696. Xlong d;
  1697. X{
  1698. X    extern long duback;
  1699. X
  1700. X    return( duback += ( d * 86400 ));
  1701. X}
  1702. X
  1703. X/*
  1704. X    Check see if string starts with a valid month name.  Return
  1705. X    0 if not,  1-12 if so.
  1706. X*/
  1707. Xismonth( s )
  1708. Xchar *s;
  1709. X{
  1710. X    extern int eod;
  1711. X    static char *months[] = { "jan", "feb", "mar", "apr", "may", "jun",
  1712. X                              "jul", "aug", "sep", "oct", "nov", "dec", "" };
  1713. X    int i;
  1714. X
  1715. X    for( i = 0 ; *months[i] ; i++ )    {
  1716. X        if( ! strncmp( s, months[i], 3 ))
  1717. X            return( ++i );
  1718. X    }
  1719. X    return( 0 );
  1720. X}
  1721. X
  1722. X/*
  1723. X    Check see if string starts with a valid day name.  Return
  1724. X    -1 if not, day of week (0 = sun) if so.
  1725. X*/
  1726. Xisday( s )
  1727. Xchar * s;
  1728. X{
  1729. X    static char *days[] = { "sun", "mon", "tue", "wed", "thu",
  1730. X        "fri", "sat", "" };
  1731. X    int i;
  1732. X
  1733. X    for( i = 0 ; *days[i] ; i++ )    {
  1734. X        if( ! strncmp( s, days[i], 3 ))
  1735. X            return( i );
  1736. X    }
  1737. X    return( -1 );
  1738. X}
  1739. X
  1740. Xvoid copytime( t, n )
  1741. Xstruct tm *t;
  1742. Xstruct tm *n;
  1743. X{
  1744. X    n->tm_sec    = t->tm_sec;
  1745. X    n->tm_min    = t->tm_min;
  1746. X    n->tm_hour    = t->tm_hour;
  1747. X    n->tm_mday    = t->tm_mday;
  1748. X    n->tm_mon    = t->tm_mon;
  1749. X    n->tm_year    = t->tm_year;
  1750. X    n->tm_wday    = t->tm_wday;
  1751. X    n->tm_yday    = t->tm_yday;
  1752. X    n->tm_isdst    = t->tm_isdst;
  1753. X#ifndef    BSD
  1754. X    n->tm_tzadj    = t->tm_tzadj;
  1755. X    strcpy( n->tm_name, t->tm_name );
  1756. X#endif    /* BSD */
  1757. X}
  1758. X
  1759. Xshowtime( t )
  1760. Xlong *t;
  1761. X{
  1762. X    printf( "%s", ctime( t ) );
  1763. X}
  1764. X
  1765. END_OF_FILE
  1766. if test 3793 -ne `wc -c <'tfix.c'`; then
  1767.     echo shar: \"'tfix.c'\" unpacked with wrong size!
  1768. fi
  1769. # end of 'tfix.c'
  1770. fi
  1771. echo shar: End of shell archive.
  1772. exit 0
  1773.